package com.cn.tianxin.ssserver.controller;

import com.cn.tianxin.ssserver.constants.WeixinConstans;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@RestController
@RequestMapping("/weixin")
public class WeixinController {



    @RequestMapping("/verification")
    public String verification(String signature,String timestamp,String nonce,String echostr){

        // 验证消息是否来自微信
        // 1）将token、timestamp、nonce三个参数进行字典序排序 2）将三个参数字符串拼接成一个字符串进行sha1加密 3）开发者获得加密后的字符串可与signature对比，标识该请求来源于微信

        String token = WeixinConstans.token;
        String[] array = {token, timestamp, nonce};
        Arrays.sort(array);

        System.out.println(array);

        return echostr;
    }

}
